/*
 * DppmBuffer.h
 *
 *  Created on: 31/01/2014
 *      Author: Bruno
 */

#ifndef DPPMBUFFER_H_
#define DPPMBUFFER_H_

#include <stdlib.h>
#include <queue>
#include "DppmParams.h"
#include "SortedBuffer.h"
#include <pthread.h>
#include <iostream>


//incluir pthreads utilizar un mutex local al objeto
using namespace std;

class DppmBuffer {

private:

	SortedBuffer bufferShare; 	//tuplas que a tomar en cuenta en el balanceo
	queue<Tuple*> buffer;	 	//tuplas que estan por terminar
	int sizeT;
	int share_param;

public:
	DppmBuffer();
	void setShareParam(int sp);
	int getShareParam();
	void init(int** buffRecv, int sizeT, int countT);
	void insert(int** buffRecv, int sizeT, int countT);
	int getKTuples(int count, int** &buff);
	void push(Tuple* t);
	Tuple* pop();
	int getCountT(); //cantidad de tuplas
	bool isEmpty();
	void print();
	virtual ~DppmBuffer();
};

int* clone(int* buff, int size);
Tuple * cloneTupla(Tuple * t, int numAct);
Tuple* createTupla(int countElem);
void destroyTupla(Tuple * &t);
Tuple * makeTuplefromBuff(int * buff, int sizeT);
int * makeBufffromTuple(Tuple * t, int sizeT);


#endif /* DPPMBUFFER_H_ */
